gpNamespace.BottomLayer = cc.Layer.extend({
	ctor: function () {
		this._super();
		this.init();
	},

	init: function () {
		ccs.armatureDataManager.addArmatureFileInfo(
				gpNamespace.eggAnimationRes.Egg_png,
				gpNamespace.eggAnimationRes.Egg_plist,
				gpNamespace.eggAnimationRes.Egg_json);
		ccs.armatureDataManager.addArmatureFileInfo(
				gpNamespace.xsjlAnimationRes.Xsjl_png,
				gpNamespace.xsjlAnimationRes.Xsjl_plist,
				gpNamespace.xsjlAnimationRes.Xsjl_json);
		var size = cc.winSize;
		var middleLen = 150;

		//底部背景
		var BottomBg = new cc.MenuItemImage(
				gpNamespace.mainSenceFirst.BottomLayerBackground,
				gpNamespace.mainSenceFirst.BottomLayerBackground,
				function () {

				}, this);
		BottomBg.attr({
			x: size.width / 2,
			y: 0,
			anchorX: 0.5,
			anchorY: 0
		});
		this.addChild(BottomBg);
		//商城
		var Store = new cc.MenuItemImage(
				gpNamespace.mainSenceFirst.BottomLayerShopButton,
				gpNamespace.mainSenceFirst.BottomLayerShopButton,
				function (sender) {
					Store.runAction(cc.sequence(cc.scaleTo(0.1, 1.04, 0.96), cc.scaleTo(0.1, 0.96, 1.04), cc.scaleTo(0.1, 1, 1)));
					//xinyou.netManager.inPhysicalExchange();//获取商城实物奖品的信息
					cc.log("商城");
					gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
					tyNamespace.setMenuEnable(sender);
					var runningScene = cc.director.getRunningScene();
					var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
					var modelLayer = new tyNamespace.ModelLayer(70);
					modelLayer.setTouchArea(cc.size(1210, 570), cc.p(35, 35));
					modelLayerCancelable.addChild(modelLayer);
					runningScene.addChild(modelLayerCancelable, 10);
					var scLayer = new gpNamespace.ScLayer();
					scLayer.attr({
						//左上角坐标
						x: 0,
						y: cc.winSize.height
					});
					modelLayer.addChild(scLayer);
					tyNamespace.AnimationManager.nodeJumpShow(scLayer, -cc.winSize.height);
				}, this);
		Store.attr({
			x: Store.width / 2 + 125,
			y: 0,
			anchorX: 0.5,
			anchorY: 0
		});

		//公告
		var Notice = new cc.MenuItemImage(
				gpNamespace.mainSenceFirst.BottomLayerNoticeButton,
				gpNamespace.mainSenceFirst.BottomLayerNoticeButton,
				function (sender) {
					Notice.runAction(cc.sequence(cc.scaleTo(0.1, 1.04, 0.96), cc.scaleTo(0.1, 0.96, 1.04), cc.scaleTo(0.1, 1, 1)));
					xinyou.netManager.getGonggao(1);//获取公告1：列表 2：详情,
					cc.log("公告");     
					gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
					tyNamespace.setMenuEnable(sender);
					var runningScene = cc.director.getRunningScene();
					var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
					var modelLayer = new tyNamespace.ModelLayer(70);
					modelLayer.setTouchArea(cc.size(1138, 576), cc.p(72, 70));
					modelLayerCancelable.addChild(modelLayer);
					runningScene.addChild(modelLayerCancelable, 10);
					var gonggaoLayer = new gpNamespace.GonggaoLayer();
					gonggaoLayer.attr({
						//左上角坐标
						x: 0,
						y: cc.winSize.height
					});
					modelLayer.addChild(gonggaoLayer);
					tyNamespace.AnimationManager.nodeJumpShow(gonggaoLayer, -cc.winSize.height);       
				}, this);
		Notice.attr({
			x: Store.getPositionX() + Store.width / 2 + Notice.width / 2 + middleLen,
			y: 0,
			anchorX: 0.5,
			anchorY: 0,
		});

		//帮助
		var Task = new cc.MenuItemImage(
				gpNamespace.mainSenceFirst.BottomLayerHelpButton,
				gpNamespace.mainSenceFirst.BottomLayerHelpButton,
				function (sender) {
					cc.log("帮助");
					Task.runAction(cc.sequence(cc.scaleTo(0.1, 1.04, 0.96), cc.scaleTo(0.1, 0.96, 1.04), cc.scaleTo(0.1, 1, 1)));
					gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
					tyNamespace.setMenuEnable(sender);
					var runningScene = cc.director.getRunningScene();
					var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
					var modelLayer = new tyNamespace.ModelLayer(70);
					modelLayer.setTouchArea(cc.size(1050, 550), cc.p(118,70));
					modelLayerCancelable.addChild(modelLayer);
					runningScene.addChild(modelLayerCancelable, 10);
					var helpLayer = new gpNamespace.HelpLayer();
					helpLayer.attr({
						//左上角坐标
						x: 0,
						y: cc.winSize.height
					});
					modelLayer.addChild(helpLayer);
					tyNamespace.AnimationManager.nodeJumpShow(helpLayer, -cc.winSize.height);
				}, this);
		Task.attr({
			x: Notice.getPositionX() + Notice.width / 2 + Task.width / 2 + middleLen,
			y: 0,
			anchorX: 0.5,
			anchorY: 0,
		});

		//邮件
		var email = new cc.MenuItemImage(
				gpNamespace.mainSenceFirst.BottomLayerMailButton,
				gpNamespace.mainSenceFirst.BottomLayerMailButton,
				function (sender) {
					email.runAction(cc.sequence(cc.scaleTo(0.1, 1.04, 0.96), cc.scaleTo(0.1, 0.96, 1.04), cc.scaleTo(0.1, 1, 1)));
					tyNamespace.setMenuEnable(sender);
					xinyou.netManager.getMail(1);//获取邮件
					gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
					cc.log("邮件");
					var runningScene = cc.director.getRunningScene();
					var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
					var modelLayer = new tyNamespace.ModelLayer(70);
					modelLayer.setTouchArea(cc.size(1040, 550), cc.p(120, 50));
					modelLayerCancelable.addChild(modelLayer);
					runningScene.addChild(modelLayerCancelable, 10);
					var yjLayer = new gpNamespace.YjLayer();
					yjLayer.attr({
						//左上角坐标
						x: 0,
						y: cc.winSize.height
					});
					modelLayer.addChild(yjLayer);
					tyNamespace.AnimationManager.nodeJumpShow(yjLayer, -cc.winSize.height);
				}, this);
		email.attr({
			x: Task.getPositionX() + Task.width / 2 + email.width / 2 + middleLen,
			y: 0,
			anchorX: 0.5,
			anchorY: 0,
		});

		//新手大礼包
		/*var xsDlbBt = new cc.MenuItemImage(
        		gpNamespace.ty.Ty_XsDlbOn,
        		gpNamespace.ty.Ty_XsDlbOn,
        		function (sender) {
        			cc.log("新手大礼包");
        			tyNamespace.setMenuEnable(sender);
        			gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
        			var runningScene = cc.director.getRunningScene();
        			var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
        			var modelLayer = new tyNamespace.ModelLayer(70);
        			modelLayer.setTouchArea(cc.size(555, 490), cc.p(365, 111));
        			modelLayerCancelable.addChild(modelLayer);
        			runningScene.addChild(modelLayerCancelable, 10);
        			var czLayer = new gpNamespace.HhdlbLayer() ;
        			czLayer.attr({
        				//左上角坐标
        				x: 0,
        				y: cc.winSize.height
        			});
        			modelLayer.addChild(czLayer);
        			tyNamespace.AnimationManager.nodeJumpShow(czLayer, -cc.winSize.height);
        		}, this);
        xsDlbBt.attr({
        	x: 1170,
        	y: 300,
        	anchorX: 0,
        	anchorY: 0,
        });*/

		//底部菜单栏选择
		var TopMenu = new cc.Menu(Store, Notice, email, Task);
		TopMenu.x = 0;
		TopMenu.y = 0;
		TopMenu.anchorX = 0;
		TopMenu.anchorY = 0;
		//cc.log(menu.left + "," + menu.top);
		this.addChild(TopMenu,5);

		//新手大礼包动画
		var xslbAvi = new ccs.Armature("cdd_zjj_xinshoudaolibao_dh");
		xslbAvi.getAnimation().playWithIndex(0);
		xslbAvi.getAnimation().setSpeedScale(1);
		xslbAvi.setScale(1);
		xslbAvi.setAnchorPoint(1, 0.5);
		xslbAvi.setPosition(size.width-30, 340);
//		eggAvi.setTag(1010);
		this.xslbAvi = xslbAvi;
		this.addChild(xslbAvi,3);
		xslbAvi.getAnimation().setMovementEventCallFunc(null, this);

		//鸡蛋动画
		var eggAvi = new ccs.Armature("dh_zjm_zjdddd");
//		eggAvi.getAnimation().playWithIndex(0);
		eggAvi.getAnimation().play("Animation_zjm_jd");
		eggAvi.getAnimation().setSpeedScale(1);
		eggAvi.setScale(1);
		eggAvi.setAnchorPoint(1, 0.5);
		eggAvi.setPosition(size.width-30, 150);
//		eggAvi.setTag(1010);
		this.eggAvi = eggAvi;
		this.addChild(eggAvi,3);
		eggAvi.getAnimation().setMovementEventCallFunc(null, this);

		var eggTouchItem =new cc.MenuItemSprite(new cc.Sprite(), new cc.Sprite(),this.TouchCallback,this);
		eggTouchItem.setContentSize(cc.size(74, 112));
		eggTouchItem.setAnchorPoint(1, 0.5);
		eggTouchItem.setPosition(size.width-30, 150);
		eggTouchItem.setUserData(1);

		var xslbTouchItem =new cc.MenuItemSprite(new cc.Sprite(), new cc.Sprite(),this.TouchCallback,this);
		xslbTouchItem.setContentSize(cc.size(74, 112));
		xslbTouchItem.setAnchorPoint(1, 0.5);
		xslbTouchItem.setPosition(size.width-30, 340);
		xslbTouchItem.setUserData(2);

		var eggmenu = new cc.Menu(eggTouchItem,xslbTouchItem);
		eggmenu.attr({
			x:0,
			y:0,
			anchorX:0,
			anchorY:0
		});
		this.addChild(eggmenu);

		var xsDlbTips = new cc.MenuItemImage(gpNamespace.mainSenceFirst.DialogGiftBag,gpNamespace.mainSenceFirst.DialogGiftBag,this.tipsCallback,this);
		xsDlbTips.attr({
			x: 1208,
			y: 410
		});
		tyNamespace.AnimationManager.nodeDaxiaoda(xsDlbTips,0.6,0.3);
		var tipsmenu = new cc.Menu(xsDlbTips);
		tipsmenu.attr({
			x:0,
			y:0,
			anchorX:0,
			anchorY:0
		});
		this.tipsmenu = tipsmenu;
		this.addChild(tipsmenu);

		gpNamespace.TyNetManager.getInstance().setBottomLayer(this);
		this.schedule(this.eggSchedule, 15);
	},

	setEggTips:function(){
//		cc.log("################setEggTips");
		if(this.getChildByTag(123)){
			this.getChildByTag(123).removeFromParent(true);
		}
		var tips = gpNamespace.mainSenceFirst.DialogFreeGoldenEgg;
		if(userInfo.isKickEgg){
			tips = gpNamespace.mainSenceFirst.DialogGoldenEgg;
		}
		
		eggTips= new cc.MenuItemImage(tips,tips,this.tipsCallback,this);
		eggTips.attr({
			x: 1208,
			y: 230
		});
		eggTips.setVisible(false);
		var tipsmenu = new cc.Menu(eggTips);
		tipsmenu.attr({
			x:0,
			y:0,
			anchorX:0,
			anchorY:0
		});
		
		var eggsprite = new cc.Sprite();
		eggsprite.attr({
			x: 1208,
			y: 230
		});
		eggsprite.setScale(0);
		tyNamespace.AnimationManager.nodeDaxiaoda(eggsprite, 0.6, 0.3);
		eggsprite.setTag(123);
		this.addChild(eggsprite);
		var tipsArray = 0;
		if(userInfo.isKickEgg){
			tipsArray = 37;
		}else{
			tipsArray = 38;
		}
		///////////////动画开始//////////////////////
		var animation = new cc.Animation();								
		for (var i = 36; i <= tipsArray; i++) {
			var frameName = "pdk_zjm_0" + i + "u.png";								
			cc.log("frameName >>>>>>>>>>>>>>>>> " + frameName);
			var spriteFrame = cc.spriteFrameCache.getSpriteFrame(frameName); 
			animation.addSpriteFrame(spriteFrame); 							
		}
		animation.setDelayPerUnit(5);           //设置两个帧播放时间
		animation.setRestoreOriginalFrame(true);    //动画执行后还原初始状态		
		var action = cc.animate(animation); 
		eggsprite.runAction(cc.repeatForever(action)); 	
		
		tipsmenu.setTag(123);
		this.tipsmenu = tipsmenu;
		this.addChild(tipsmenu);
	},

	tipsCallback:function(sender){
		sender.runAction(new cc.FadeOut(0.5));
	},

	TouchCallback:function(sender){

		tyNamespace.setMenuEnable(sender);
		var index = sender.getUserData();
		cc.log("index:"+index);
		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);

		var layer = null;
		if(index == 1){
			cc.log("砸金蛋");
			var runningScene = cc.director.getRunningScene();
			var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
			var modelLayer = new tyNamespace.ModelLayer(70);
			modelLayer.setTouchArea(cc.size(1140, 560), cc.p(66, 94));
			modelLayerCancelable.addChild(modelLayer);
			runningScene.addChild(modelLayerCancelable, 10);
			var zjdlayer = new gpNamespace.ZjdLayer();//砸金蛋
			zjdlayer.attr({
				//左上角坐标
				x: 0,
				y: cc.winSize.height
			});
			modelLayer.addChild(zjdlayer);
			tyNamespace.AnimationManager.nodeJumpShow(zjdlayer, -cc.winSize.height);
		}else{
			var runningScene = cc.director.getRunningScene();
			var modelLayerCancelable = new tyNamespace.ModelLayerCancelable();
			var modelLayer = new tyNamespace.ModelLayer(70);
			modelLayer.setTouchArea(cc.size(875, 605), cc.p(200, 75));
			modelLayerCancelable.addChild(modelLayer);
			runningScene.addChild(modelLayerCancelable, 10);
			var hhdlblayer = new gpNamespace.HhdlbLayer();//新手礼包
			hhdlblayer.attr({
				//左上角坐标
				x: 0,
				y: cc.winSize.height
			});
			modelLayer.addChild(hhdlblayer);
			tyNamespace.AnimationManager.nodeJumpShow(hhdlblayer, -cc.winSize.height);
		}
	},

	eggSchedule:function(){
		this.eggAvi.getAnimation().playWithIndex(0);
		this.xslbAvi.getAnimation().playWithIndex(0);
	},

	setMailTips:function(){//显示邮件数提示
		var notReadNum = 0;
		var tipsPicPath = null;
		for(var i = 0; i < userMailInfo.itemCount ; i++){
			userMailInfo && userMailInfo.mails[i][1] == 0 && notReadNum++; 
		}
		cc.log("###########notReadNum:"+notReadNum);
		if(notReadNum != 0){
			this.getChildByTag(233) && this.getChildByTag(233).removeFromParent();
			if(notReadNum>0 && notReadNum<4){
				tipsPicPath = "#sz_cdd_zjm_01"+(notReadNum-1)+"u.png"
			}else{
				tipsPicPath = "#sz_cdd_zjm_019u.png";
			}
			var tipsPic = new cc.Sprite(tipsPicPath);
			tipsPic.attr({
				x:1135,
				y:70
			});
			tipsPic.setTag(233);
			this.addChild(tipsPic,10);
		}else{
			currentNetManager=gpNamespace.NetManager.getInstance();
			if(currentNetManager.isReconnnect){
			}else{
				this.getChildByTag(233) && this.getChildByTag(233).removeFromParent();
			}
		}
	},
});